package com.byapp.fast.common.converter;

import com.byapp.fast.modules.order.entity.ItemContentEntity;
import com.byapp.fast.modules.order.entity.OrderItemEntity;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

public class ItemContentConverter implements ConverterFactory<ItemContentEntity, OrderItemEntity> {


    @Override
    public ItemContentEntity create(OrderItemEntity orderItem) {
        return new ItemContentEntity()
                .setItemId(orderItem.getItemId())
                .setUserId(orderItem.getUserId())
                .setMatchId(orderItem.getBalanceMatchId())
                .setMatchOdds(orderItem.getOdds())
                .setBuyCode(orderItem.getCodes())
                .setBuyType(orderItem.getBuyType())
                .setPlayId(orderItem.getPlayId())
                .setPlayType(orderItem.getPlayType())
                .setClientProperties(orderItem.getCodeTeamName())
                .setOddsId(orderItem.getOddsId())
                .setHandicap(orderItem.getHandicap());
    }


    public static List<ItemContentEntity> mapToTarget(List<OrderItemEntity> list) {
        return !CollectionUtils.isEmpty(list) ? list.stream()
                .map(new ItemContentConverter()::create)
                .collect(Collectors.toList()) : null;
    }

    public static ItemContentEntity mapToTarget(OrderItemEntity orderItemEntity) {
        return new ItemContentConverter().create(orderItemEntity);
    }

}